home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / EXEC.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  6KB  |  249 lines

  1. cseg    segment para public 'code'
  2. org    100h
  3. exec    proc far
  4.  
  5. ; This program is used as a program loader. After being used to load
  6. ; a program, it can be used to load up to 4 programs, including return of
  7. ; control to the original program. DOS 2.00 or later is required.
  8. ; To use it with interpretive BASIC, enter 'EXEC BASIC.COM progname'.
  9. ; See the sample program RUNIT.BAS for an example of the use of this
  10. ; program.
  11.  
  12.     assume cs:cseg,ds:cseg,ss:nothing,es:nothing
  13.  
  14. p000:    mov dx,offset copyr    ; print copyright message
  15.     call p500
  16.     mov ah,30h        ; get dos version
  17.     int 21h
  18.     cmp al,0        ; is al zero?
  19.     jnz p005        ; no - it's dos 2.00 or later
  20.     mov dx,offset baddos
  21.     call p500        ; print message
  22.     jmp p099        ; terminate
  23.  
  24. p005:                ; set PSP pointer in communications area
  25.     push ds
  26.     xor ax,ax        ; make it zero
  27.     mov ds,ax
  28.     mov si,4f0h        ; set pointer to subroutine entry point
  29.     mov ax,offset another
  30.     mov [si],ax        ; save is dos comm. area
  31.     add si,2        ; set pointer to PSP
  32.     mov ax,es        ; get PSP segment
  33.     mov [si],ax        ; save in dos comm. area
  34.     pop ds            ; restore ds
  35.  
  36. p010:                ; check command line
  37.     mov si,80h        ; get command line
  38. p015:                ; restart entry point
  39.     mov al,[si]
  40.     cmp al,0        ; anything there?
  41.     jnz p020        ; yes
  42.     mov dx,offset nocomm    ; no
  43.     call p500        ; print message
  44.     jmp p099        ; terminate
  45.  
  46. p020:                ; copy command line
  47.     mov ch,0
  48.     mov cl,al
  49.     inc si            ; check next char
  50.     mov al,[si]
  51.     cmp al,' '              ; is it a leading space?
  52.     jnz p021        ; no
  53.     inc si            ; yes - ignore it
  54.     dec cl
  55. p021:
  56.     push cx         ; save char count
  57.     mov al,0        ; initialize work area
  58.     mov cx,offset stak
  59.     mov di,offset prog
  60.     sub cx,di
  61.     repnz stosb        ; zero it
  62.     pop cx            ; restore char count
  63.  
  64.     mov di,offset prog    ; point to target area
  65. p022:
  66.     mov al,[si]        ; get char
  67.     cmp al,' '              ; space?
  68.     jz p025         ; yes
  69.     cmp al,'/'              ; slash?
  70.     jz p025         ; yes
  71.     mov [di],al        ; copy char
  72.     inc si
  73.     inc di
  74.     loop p022
  75. p025:
  76.     push si         ; save command start point
  77.     mov di,offset comm
  78.     mov [di],cl        ; set remaining length
  79.     inc di
  80.     repnz movsb        ; copy command portion
  81.     mov al,0dh
  82.     mov [di],al        ; add carriage return
  83.  
  84.     pop si            ; get command start point
  85.     mov di,offset fcb1
  86.     mov ah,29h
  87.     mov al,1        ; scan off leading separators
  88.     int 21h         ; parse filename for fcb1
  89.  
  90.     mov di,offset fcb2
  91.     mov ah,29h
  92.     mov al,1
  93.     int 21h         ; parse filename for fcb2
  94.  
  95. p040:                ; release memory
  96.     mov ax,offset endprog    ; number of paragraphs to keep
  97.     add ax,15        ; last address plus 15
  98.     mov cl,4
  99.     sar ax,cl        ; divide by 16 to get paragraphs
  100.     mov bx,ax
  101.     mov ah,4ah
  102.     int 21h         ; free memory
  103.     jnc p050        ; no error
  104.     aam
  105.     add ax,3030h
  106.     xchg ah,al
  107.     mov si,offset memerr
  108.     mov [si],ax
  109.     mov dx,offset badmem
  110.     call p500
  111.     jmp p099
  112.  
  113. p050:                ; point to command line
  114.     mov si,offset parm2
  115.     mov dx,offset comm
  116.     mov [si],dx
  117.     mov ax,ds
  118.     mov [si+2],ax
  119.  
  120. p060:                ; point to fcbs
  121.     mov si,offset parm3    ; fcb 1
  122.     mov dx,offset fcb1
  123.     mov [si],dx
  124.     mov ax,ds
  125.     mov [si+2],ax
  126.  
  127.     mov si,offset parm4    ; fcb 2
  128.     mov dx,offset fcb2
  129.     mov [si],dx
  130.     mov ax,ds
  131.     mov [si+2],ax
  132.  
  133. p070:                ; make call
  134.     mov si,offset stak    ; save stack
  135.     mov [si],sp
  136.     mov [si+2],ss
  137.  
  138.     mov ah,4bh        ; load prog
  139.     mov al,0        ; load & execute
  140.     mov dx,offset prog    ; point to prog name
  141.     mov bx,offset parm1    ; point to parameter
  142.     int 21h         ; load & execute program
  143.  
  144.     mov bx,cs        ; restore stack
  145.     mov ds,bx
  146.     mov es,bx
  147.     mov si,offset stak
  148.     cli            ; no interrupts
  149.     mov sp,[si]
  150.     mov ss,[si+2]
  151.     sti            ; allow interrupts
  152.     jnc p080        ; no error
  153.     aam            ; get error code
  154.     add ax,3030h
  155.     xchg ah,al
  156.     mov si,offset callerr
  157.     mov [si],ax
  158.     mov dx,offset badcal1    ; print error message
  159.     call p500
  160.     mov si,offset comm
  161.     mov al,'$'
  162.     mov [si],al
  163.     mov dx,offset prog
  164.     call p500
  165.     mov dx,offset badcal2
  166.     call p500
  167.     jmp p099
  168.  
  169. p080:                ; start next program
  170.     mov si,offset another
  171.     mov cx,[si]        ; any more to execute?
  172.     jcxz p099        ; no
  173.     dec cx
  174.     mov [si],cx        ; decrement counter
  175.     mov si,offset prog1    ; point to first program
  176.     mov ax,80        ; size of each program name
  177.     mul cx
  178.     add si,ax        ; point to next program
  179.     jmp p015        ; execute it
  180.  
  181. p099:                ; end
  182.     push ds
  183.     xor ax,ax        ; make it zero
  184.     mov ds,ax
  185.     mov si,4f0h        ; word at 0:4f0 is dos comm. area
  186.     mov [si],ax        ; zero it
  187.     add si,2        ; next word
  188.     mov [si],ax        ; zero it too
  189.     pop ds            ; restore ds
  190.     int 20h         ; terminate
  191.  
  192. p500    proc near        ; print message
  193.     push ax
  194.     mov ah,9
  195.     int 21h
  196.     pop ax
  197.     ret
  198. p500    endp
  199.  
  200.     ; messages
  201.  
  202. copyr    db 'EXEC - Copyright 1983 Data Base Decisions',10,13,'$'
  203. baddos    db 'DOS 2.00 or later required',07,'$'
  204. nocomm    db 'No file entered',07,'$'
  205.  
  206. badmem    db 'Unable to release memory.  Error: '
  207. memerr    dw 0
  208.     db 7,'$'
  209.  
  210. badcal1 db 'Unable to execute program $'
  211.  
  212. badcal2 db '  Error: '
  213. callerr dw 0
  214.     db 7,'$'
  215.  
  216.     ; work area
  217.  
  218. prog    db 80 dup(0)        ; program name
  219. comm    db 80 dup(0)        ; command line parameters - may be overridden
  220.                 ; by fcb(s)
  221. fcb1    db 40 dup(0)        ; fcb 1
  222. fcb2    db 40 dup(0)        ; fcb 2
  223.  
  224. stak    dw 0            ; save sp
  225.     dw 0            ; save ss
  226.  
  227.     ; program data area
  228.  
  229. signature dw 01237h        ; used by application to validate that
  230.                 ; EXEC.COM is really there
  231. another dw 0            ; execute another? 0=no, 1=yes
  232. prog1    db 80 dup(0)        ; 1st program
  233. prog2    db 80 dup(0)        ; 2nd program
  234. prog3    db 80 dup(0)        ; 3rd program
  235. prog4    db 80 dup(0)        ; 4th program
  236.  
  237.     ; exec parameter block
  238.  
  239. parm1    dw 0            ; environment
  240. parm2    dd 0            ; command line
  241. parm3    dd 0            ; default FCB
  242. parm4    dd 0            ; second default FCB
  243.  
  244. endprog db 0
  245.  
  246. exec    endp
  247. cseg    ends
  248. end    exec
  249.